<?php
session_start();
include('fungsi_admin.php');
if (!empty($_SESSION['user'])){
$isi = mysql_fetch_assoc(tampil_ubah($_GET['id']));
?>
<html>
	<head>
		<title>BudiNews.com</title>
		<link rel="shortcut icon" href="../admin/css/mos-css/img/quote.png">
		<!-- Pemanggilan gambar favicon-->
		<link rel="stylesheet" type="text/css" href="../admin/css/mos-css/mos-style.css">
		<!--pemanggilan file css-->
	</head>
	<body>
		<div id="header">
			<div class="inHeader">
				<div class="mosAdmin">
					selamat datang di halaman Admin BudiNews.com
					<br/>
					<a href="keluar.php">Keluar</a>
				</div>
				<div class="clear">
				</div>
			</div>
		</div>
		<div id="wrapper">
			<div id="leftBar">
				<ul>
					<li>
						<a href="dashboard.php">Berita</a>
					</li>
					<li>
						<a href="kategori_tampil.php">Kategori</a>
					</li>
					<li>
						<a href="keluar.php">Keluar</a>
					</li>
				</ul>
			</div>
			<div id="rightContent">
				<h3>Halaman Edit Berita</h3>
				<center>
					<form action="" method="post" enctype="multipart/form-data">
						<table>
							<tbody>
								<tr>
									<td>
									<b>Judul Berita</b>
									</td>
									<td>
									<input type="text" name="judul" value="<? echo $isi['judul'];?>">
									</td>
								</tr>
								<tr>
									<td>
									<b>Isi Berita</b>
									</td>
									<td>
									<textarea cols="30" rows="20" name="detail">
										<?echo $isi['detail'];?>
									</textarea>
									</td>
								</tr>
								<tr>
									<td>
									<b>Kategori</b>
									</td>
									<td>
									<select name="kategori">
										<option value="-">Pilih Kategori</option>
										<?php
										kategori($isi['id_kategori']);
										?>
									</select>
									</td>
								</tr>
								<tr>
									<td>
									<b>Status</b>
									</td>
									<td>
									<select name="status">
										<option value="-">Pilih Status</option>
										<option value="1" <?
										if($isi['status'] == 1) { echo "selected=selected";
										}
										?>>headline</option>
										<option value="2" <?
										if($isi['status'] == 2) { echo "selected=selected";
										}
										?>>feature</option>
										<option value="3" <?
										if($isi['status'] == 3) { echo "selected=selected";
										}
										?>>biasa</option>
									</select>
									</td>
								</tr>
								<tr>
									<td>
									<b>Gambar Berita</b>
									</td>
									<td>
									<img src="../gambar/<?php echo $isi['gambar'];?>" width="100px" height="100px"/>
									<br/>
									<br/>
									<?php echo $isi['gambar'];?>
									</td>
								</tr>
								<tr>
									<td>
									<b>Ganti Gambar</b>
									</td>
									<td>
									<input type="file" name="gambar">
									</td>
								</tr>
								<tr>
									<td></td>
									<td>
									<input type="submit" value="POST">
									</td>
								</tr>
							</tbody>
						</table>
					</form>
				</center>
			</div>
			<div class="clear">
			</div>
			<div id="footer">
				&copy; 2014 Created by |
				<a href="../pwl">BudiNews.com</a>
			</div>
		</div>
	</body>
</html>
<?php
if(!empty($_POST)) {

	$order = array("\"", "\'");
	$replace = '&#34;';
	$ber = str_replace($order, $replace, $_POST['detail']);
	$pic = $_FILES['gambar']['name'];
	if(empty($pic)) {
		$gambar = $isi['gambar'];
	} else {
		$gambar = $_FILES['gambar']['name'];
	}
	move_uploaded_file($_FILES['gambar']['tmp_name'], "../gambar/" . $_FILES['gambar']['name']);
	$masuk = ubah($_POST['judul'], trim($ber), $gambar, $_POST['kategori'], $_POST['status'], $isi['id_berita']);
}
}else{
echo "anda tidak berhak";
}
?>